package net.sxjr.protal.timer;

import lombok.extern.slf4j.Slf4j;
import net.sxjr.mbg.entity.ZhfxYj;
import net.sxjr.protal.mapper.ZhfxMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;

@Slf4j
@Component
public class ZhfxTimer {
    @Autowired
    private ZhfxMapper zhfxMapper;
    @Scheduled(cron = "0 50 23 28-31 * ?")//每个月 最后一天
    public void zhfx(){
        Calendar f = Calendar.getInstance();
        if (f.get(Calendar.DATE) != f.getActualMaximum(Calendar.DATE)) return;
        log.error("综合分析定时器启动");
        //获取当前时间
        Calendar c = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM" );
        String month = sdf.format(c.getTime());

        ZhfxYj zhfxYj = new ZhfxYj();
        zhfxYj.setMonth(month);

        Integer wdjdhgs = zhfxMapper.wdjdhgs();
        zhfxYj.setPingjiaHege(wdjdhgs);
        zhfxYj.setPingjiaBuhege(zhfxMapper.wdjdzs() - wdjdhgs);

        //预警人数
        Integer currentMonthsqyjrs = zhfxMapper.currentMonthsqyjrs();
        Integer currentMonthszjdrs = zhfxMapper.currentMonthszjdrs();
        Integer currentMonthshpjrs = zhfxMapper.currentMonthshpjrs();
        zhfxYj.setYujingSq(currentMonthsqyjrs);
        zhfxYj.setYujingSz(currentMonthszjdrs);
        zhfxYj.setYujingSh(currentMonthshpjrs);
        zhfxYj.setPersonNum(currentMonthsqyjrs+currentMonthszjdrs+currentMonthshpjrs);
        //三重一大
        //本月合格次数
        Integer szydhgs = zhfxMapper.szydhgs();
        zhfxYj.setPingjiaHegeSzyd(szydhgs);
        zhfxYj.setPingjiaBuhegeSzyd(zhfxMapper.szydzs()-szydhgs);


        zhfxYj.setYujingSqSzyd(zhfxMapper.sqyjrsszyd());
        zhfxYj.setYujingSzSzyd(zhfxMapper.szjdrsszyd());
        zhfxYj.setYujingShSzyd(zhfxMapper.shpjrszdyd());


        //项目管理
        //本月合格次数
        Integer xmjdhgs = zhfxMapper.xmjdhgs();
        zhfxYj.setPingjiaHegeXmgl(xmjdhgs);
        zhfxYj.setPingjiaBuhegeXmgl(zhfxMapper.xmjdzs() - xmjdhgs);

        zhfxYj.setYujingSqXmgl(zhfxMapper.sqyjrsxmjd());
        zhfxYj.setYujingSzXmgl(zhfxMapper.szjdrsxmgl());
        zhfxYj.setYujingShXmgl(zhfxMapper.shpjrsxmgl());

        //薪酬管理
        Integer xcgljdhgs = zhfxMapper.xcgljdhgs();
        zhfxYj.setPingjiaHegeXcgl(xcgljdhgs);
        zhfxYj.setPingjiaBuhegeXcgl(zhfxMapper.xcgljdzs() - xcgljdhgs);

        zhfxYj.setYujingSqXcgl(zhfxMapper.sqyjrsxcgl());
        zhfxYj.setYujingSzXcgl(zhfxMapper.szjdrsxcgl());
        zhfxYj.setYujingShXcgl(zhfxMapper.shpjrsxcgl());

        //干部管理
        Integer gbjdglhgs = zhfxMapper.gbjdglhgs();
        zhfxYj.setPingjiaHegeGbgl(gbjdglhgs);
        zhfxYj.setPingjiaBuhegeGbgl(zhfxMapper.gbjdglzs() - gbjdglhgs);

        zhfxYj.setYujingSqGbgl(zhfxMapper.sqyjrsgbgl());
        zhfxYj.setYujingSzGbgl(zhfxMapper.szjdrssgbgl());
        zhfxYj.setYujingShGbgl(zhfxMapper.shpjrsgbgl());

        //项目管理 项目金额
        zhfxYj.setXmglxmje(zhfxMapper.xmglxiangmujiee());


        zhfxYj.insert();

    }

}
